# -*- coding: UTF-8 -*-
import os,time
import pandas as pd
proDir = os.path.split(os.path.realpath(__file__))[0]
file = "krqt.csv"
fileResult = "newresult.csv"
df = pd.read_csv(os.path.join(proDir,file), encoding='gbk')
def changeDevNo(x):
    first = int(x[0:1])
    second = int(x[1:2])
    third = int(x[2:3])
    four5 = int(x[3:5])
    six78 = int(x[5:8])
    return "03"+"-"+str(first+second+third*10)+str(four5)+"-"+str(0)+str(six78)
def test(x):
    first = "03"+"-"
    second = str(x)[:-3]
    if len(second) == 2:
        second = "00"+second
    if len(second) == 3:
        second = "0"+second    
    third = "-"+str(0)+str(x)[-3:]
    return first+second+third
def getTypeNo(x):
    if x.startswith('02-'):
        return 121
    if x.startswith('03-'):
        return 42
    if x.startswith('11-'):
        return 23
    if x.startswith('69-'):
        return 69
def getFloor(x):
    temp = int(str(x)[:-4])
    if temp>25:
        temp = -1
    return temp
def getDetail(x):
    temp = int(str(x)[:-4])
    if temp>25:
        temp = -1
    return str(temp) + '层'
def getRemark(x):
    if '层' in x:
        temp = x.split('层',1)[1]
        return str(temp)
    else:
        return str(x)
# df['shuru'] = df['shuru'].astype('str')
df['dev_no'] = df['用户编码'].map(lambda x: test(x))
df['updev_no'] = '200'
df['type_no'] = df['设备类型'].map(lambda x: getTypeNo(x))
df['system_no'] = 1
df['online_status'] = 0
df['status'] = 1
df['system_address'] = 3
df['floor']= df['用户编码'].map(lambda x: getFloor(x))
df['detail'] = df['用户编码'].map(lambda x: getDetail(x))
df['remark']= df['设备注释'].map(lambda x: getRemark(x))
df['place_id']= 1
df['location_id']=df['id']
# df["new"]=df.apply(lambda x: test(x), axis=1, result_type='expand')
df.to_csv(os.path.join(proDir,fileResult),sep=',',index = False, encoding='gbk')
# print(changeDevNo("5176666617"))
# print(test("183100"))